package com.hmall.api.dto;

import com.hmall.common.utils.UserContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;

public class FeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        //从当前线程上获取当前用户id
        Long userId = UserContext.getUser();
        if (userId != null) {
            //如果当前线程上有，就将用户id添加给Feign请求的请求头user-info
            template.header("user-info", UserContext.getUser().toString());
        }
    }
}